package com.jia.leetCode;

public class Pro1422 {
    public int maxScore(String s) {
        int ans = 0;
        int countZero = 0;
        int countOne = 0;
        int sLen = s.length();
        for(int i = 0; i < sLen; i++) {
            if(s.charAt(i) == '1') {
                ++countOne;
            }
        }
        if(s.charAt(0) == '0') {
            countZero++;
        }else {
            countOne--;
        }
        ans = Math.max(ans, countZero + countOne);
        for(int i = 1; i < sLen-1; i++) {
            if(s.charAt(i) == '0') {
                countZero++;
            }else {
                --countOne;
            }
            ans = Math.max(ans, countZero + countOne);
        }
        return ans;
    }
}
